/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package assignment_cp3120.manager.createairport;

import assignment_cp3120.ucm.UC2AL;
import assignment_cp3120.ucm.UCCreateAirports;
import java.awt.FlowLayout;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author Administrator
 */
public class CreateAirportView extends JPanel {
    private JLabel airportNameLabel;
    private JPanel airportNamePanel;
    private JTextField airportNameField;
    
    private JLabel airportCodeLabel;
    private JPanel airportCodePanel;
    private JTextField airportCodeField;    
    
    private JLabel airportTaxLabel;
    private JPanel airportTaxPanel;
    private JTextField airportTaxField;
    
    private JButton createButton;

    private CreateAirportModel model;
    
    public CreateAirportView() {        
        this(new CreateAirportModel());
    }
    public CreateAirportView(CreateAirportModel model){
        this.model = model;
        createView();
    }
    private void createView() {
        createButton = new JButton("Create");
        createButton.addActionListener(new UC2AL(new UCCreateAirports(this,model)));

        FlowLayout fl = new FlowLayout(FlowLayout.LEFT);

        airportNameLabel = new JLabel("Enter the name of this airport:");
        airportNamePanel = new JPanel(fl);
        airportNameField = new JTextField("mmmmmmmmmmmmmmmmmmmmmmmm");
        airportNameField.setPreferredSize(airportNameField.getPreferredSize());
        airportNameField.setText("");

        airportCodeLabel = new JLabel("Enter an alfa-numeric code for this airport:");
        airportCodePanel = new JPanel(fl);
        airportCodeField = new JTextField("mmm");
        airportCodeField.setPreferredSize(airportCodeField.getPreferredSize());
        airportCodeField.setText("");

        airportTaxLabel = new JLabel("Enter a tax for this airport:");
        airportTaxPanel = new JPanel(fl);
        airportTaxField = new JTextField("mmm");
        airportTaxField.setPreferredSize(airportTaxField.getPreferredSize());
        airportTaxField.setText("0");

        setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));

        airportNamePanel.add(airportNameLabel);
        airportNamePanel.add(airportNameField);
        
        airportCodePanel.add(airportCodeLabel);
        airportCodePanel.add(airportCodeField);
        
        airportTaxPanel.add(airportTaxLabel);
        airportTaxPanel.add(airportTaxField);
        
        add(airportCodePanel);
        add(airportNamePanel);
        add(airportTaxPanel);
        add(createButton);
    }
    public String getId(){
        return airportCodeField.getText();
    }
    public String getAirportName(){
        return airportNameField.getText();
    }
    public int getAirportTax(){
        return Integer.parseInt(airportTaxField.getText());
    }
    public void clearView() {
        model.loadAirports();
        this.removeAll();
        createView();
        this.validate();
    }
}
